package com.ruoyi.video.server.rtsp;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.video.domain.VideoServer;
import com.ruoyi.video.server.AbstractServer;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * RTSP流转发代理服务
 */
@Component
public class RtspServer extends AbstractServer {
    public static Integer ONLINE_KEEP = 60 * 1000 * 60;
    public static String SERVER_CODE = "rtsp";
    private static Boolean running = false;

    @Override
    public String getCode() {
        return SERVER_CODE;
    }

    @Override
    public boolean start(VideoServer videoServer) {
        Map<String,String> config = videoConfigService.selectVideoServerConfig(SERVER_CODE);

        String onlineTime = config.getOrDefault("onlineTime", "60");
        ONLINE_KEEP = Integer.parseInt(onlineTime) * 60 * 1000;

        running  = true;
        return false;
    }

    @Override
    public boolean stop(VideoServer videoServer) {
        running = false;
        return false;
    }

    @Override
    public boolean alive(VideoServer videoServer) {
        if(running) {
            new RtspTestThread().start();
        }
        return running;
    }

}
